package
{
	import com.blackjack.Dealer;
	import com.blackjack.Game;
	import com.blackjack.Player;
	import com.blackjack.cards.Stack;
	import com.menu.Menu;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.SharedObject;
	
	import flashx.textLayout.debug.assert;
	

	/* ---MetaData for Browser--- */
	[SWF(width="800", height="600",
		 scriptRecursionLimit="5000",
		 scriptTimeLimit="30",
		 frameRate="30", 
		 backgroundColor="#000000",
		 pageTitle="BlackJack")]
	
	/* ---MetaData for PreLoader--- */
	[Frame(factoryClass="com.blackjack.preloader.CustomPreloader")]
	/**
	 * An siple implementation of AbstractPreloader to create a custom preloader.
	 * 
	 * @author Bernhard Teismann
	 * @author Andre Seipelt
	 * 
	 */	
	public class BlackJack extends Sprite
	{
		private static var _instance:BlackJack;
		
		private var _sharedBlackJack:SharedObject;
		private var _game:Game;
		private var _menu:Menu;
		
		public function BlackJack()
		{
			initSharedValues();
			_instance = this;
			initValues();
			initHandler();
			initGUI();
			addChild(_game);
		}
		
		
		//Getter
		public function get game():Game{return _game;}
		public function get menu():Menu{return _menu;}
		public function get sharedBlackJack():SharedObject{return _sharedBlackJack;}
		public static function get instance():BlackJack{return _instance;}
		
		//Initialisations
		private function initValues():void{
			_game = new Game();
			_menu = new Menu();
		}
		private function initSharedValues():void{
			_sharedBlackJack = SharedObject.getLocal("sharedBlackJack");
			if(_sharedBlackJack.size == 0){
				_sharedBlackJack.data.money = 2000;
				_sharedBlackJack.data.wins = 0;
				_sharedBlackJack.data.loses = 0;
			}
		}
		
		private function initHandler():void{
			addEventListener(Event.ENTER_FRAME,updateHandler);
		}
		
		private function initGUI():void{
		}
		
		//Handler
		private function mButtonHandler(e:MouseEvent):void{
			
		}
		
		private function updateHandler(e:Event):void{
			if(_game) _game.update();
			if(_menu) _menu.update();
		}
	}
}